/*============================================================================*/
/*                              x embedded systems                            */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* %name:            app_blinking.c%
* %version:         1.0%
* %created_by:      David Robles%
* %date_created:    April 19 2012%
*=============================================================================*/
/* DESCRIPTION : Application to make blinking LEDs                            */
/*============================================================================*/
/* FUNCTION COMMENT : Code for blinking application                           */
/*                                                                            */
/*                                                                            */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.0      | 19/04/2012  |                               | David Robles     */
/* File added to project                                                      */
/*============================================================================*/

/* Includes */
/* -------- */
#include "stdtypedef.h"
#include "sw_timers.h"
#include "app_blinking.h"


/*==================================================*/ 
/* Definition of constants                          */
/*==================================================*/ 
/* BYTE constants */

/* WORD constants */
const T_UWORD cuw_timeout_timer_0 = 50;   // 50 ms timeout
const T_UWORD cuw_timeout_timer_1 = 500;  // 500 ms timeout
const T_UWORD cuw_timeout_timer_2 = 2000; // 2000 ms timeout

/* LONG and STRUCTURE constants */

/*======================================================*/ 
/* Definition of RAM variables                          */
/*======================================================*/ 
/* BYTE RAM variables */

/* WORD RAM variables */

/* LONG and STRUCTURE RAM variables */



/* Private functions prototypes */
/* ---------------------------- */
//PRIVATE_FCT void priv_func (void);


/* Exported functions prototypes */
/* ----------------------------- */
/* prototypes */
void app_blinking_init(void);
void app_blinking_LED0(void);
void app_blinking_LED1(void);
void app_blinking_LED2(void);


/* +++++++++++++++++++++ APP ++++++++++++++++++++++ */
/**************************************************************
 *  Name                 : app_blinking_init
 *  Description          : Initialize objects required for this application
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
void app_blinking_init(void)
{
  /* Initilize port for LEDs */
  /* Configure ports directions and initial value */
  TRISB = 0;
  PORTB = 0;
  sw_timers_InitTimers();
  sw_timers_StartTimer(MY_TIMER_0_);
  sw_timers_StartTimer(MY_TIMER_1_);
  sw_timers_StartTimer(MY_TIMER_2_);
}

/**************************************************************
 *  Name                 : app_blinking_LED0
 *  Description          : application for toggle LED0. This LED0 must toggle at 20 Hz
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
 void app_blinking_LED0 (void)
 {
   if(sw_timers_IsExpiredTimer(MY_TIMER_0_, cuw_timeout_timer_0))
   {
     sw_timers_StopTimer(MY_TIMER_0_);
	 PORTB ^= 0b00000100;
	 sw_timers_StartTimer(MY_TIMER_0_);
   }
 }
 
 /**************************************************************
 *  Name                 : app_blinking_LED1
 *  Description          : application for toggle LED1. This LED1 must toggle at 1 Hz
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
 void app_blinking_LED1 (void)
 {
   if(sw_timers_IsExpiredTimer(MY_TIMER_1_, cuw_timeout_timer_1))
   {
     sw_timers_StopTimer(MY_TIMER_1_);
	 PORTB ^= 0b00001000;
	 sw_timers_StartTimer(MY_TIMER_1_);
   }
 }
 
  /**************************************************************
 *  Name                 : app_blinking_LED2
 *  Description          : application for toggle LED2. This LED2 must toggle at 0.25 Hz
 *  Parameters           :  none
 *  Return               :  none
 *  Critical/explanation :  No
 **************************************************************/
 void app_blinking_LED2 (void)
 {
   if(sw_timers_IsExpiredTimer(MY_TIMER_2_, cuw_timeout_timer_2))
   {
     sw_timers_StopTimer(MY_TIMER_2_);
	 PORTB ^= 0b00010000;
	 sw_timers_StartTimer(MY_TIMER_2_);
   }
 }
 
